package services

import (
	"gin-system/models"
	"github.com/360EntSecGroup-Skylar/excelize/v2"
	"strconv"
)

func  Export(physicalList []models.Physical) error {
	file := excelize.NewFile()
	index := file.NewSheet("体检文件")
	file.SetCellValue("体检文件","A1","学号")
	file.SetCellValue("体检文件","B1","姓名")
	file.SetCellValue("体检文件","C1","性别")
	file.SetCellValue("体检文件","D1","系别")
	file.SetCellValue("体检文件","E1","年龄")
	file.SetCellValue("体检文件","F1","身高")
	file.SetCellValue("体检文件","G1","体重")
	file.SetCellValue("体检文件","H1","胸围")
	file.SetCellValue("体检文件","I1","日期")
	for index,item:= range physicalList{
		count := index+2
		file.SetCellValue("体检文件","A"+strconv.Itoa(count),item.StudentId)
		file.SetCellValue("体检文件","B"+strconv.Itoa(count),item.StudentName)
		file.SetCellValue("体检文件","C"+strconv.Itoa(count),item.Sex)
		file.SetCellValue("体检文件","D"+strconv.Itoa(count),item.Faculty)
		file.SetCellValue("体检文件","E"+strconv.Itoa(count),item.Age)
		file.SetCellValue("体检文件","F"+strconv.Itoa(count),item.Height)
		file.SetCellValue("体检文件","G"+strconv.Itoa(count),item.Weight)
		file.SetCellValue("体检文件","H"+strconv.Itoa(count),item.Chest)
		file.SetCellValue("体检文件","I"+strconv.Itoa(count),item.CreateTime)
	}
	file.SetActiveSheet(index)
	index = file.NewSheet("病例文件")
	file.SetCellValue("病例文件","A1","学号")
	file.SetCellValue("病例文件","B1","姓名")
	file.SetCellValue("病例文件","C1","性别")
	file.SetCellValue("病例文件","D1","系别")
	file.SetCellValue("病例文件","E1","诊断")
	file.SetCellValue("病例文件","F1","日期")
	for index,item:= range physicalList{
		count := index+2
		file.SetCellValue("病例文件","A"+strconv.Itoa(count),item.StudentId)
		file.SetCellValue("病例文件","B"+strconv.Itoa(count),item.StudentName)
		file.SetCellValue("病例文件","C"+strconv.Itoa(count),item.Sex)
		file.SetCellValue("病例文件","D"+strconv.Itoa(count),item.Faculty)
		file.SetCellValue("体检文件","E"+strconv.Itoa(count),item.Diagnosis)
		file.SetCellValue("体检文件","F"+strconv.Itoa(count),item.CreateTime)
	}
	file.SetActiveSheet(index)
	file.DeleteSheet("Sheet1")
	err := file.SaveAs("./work.xlsx")
	if err != nil {
		return err
	}
	return err
}